package com.nova.edc.service.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.nova.edc.dao.system.RoleDao;
import com.nova.edc.model.system.Role;
import com.nova.edc.service.system.RoleService;
import com.nova.frame.dao.criterion.Restrictions;

public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao novaRoleDao;

    @Override
    public List<Role> findAll() {
        return novaRoleDao.findAll();
    }

    @Override
    public List<Role> findByRoleParent(int roleId) {
        return novaRoleDao
                .query()
                .add(Restrictions.or(Restrictions.eq("ParentId", roleId),
                        Restrictions.eq("any", 1))).list();
    }

    @Override
    public List<Integer> findRoleId(List<Role> roleList) {
        List<Integer> roleIdList = new ArrayList<Integer>();
        for (int i = 0; i < roleList.size(); i++) {
            roleIdList.add(roleList.get(i).getId());
        }
        return roleIdList;
    }

    @Override
    public Role getById(int id) {
        return novaRoleDao.getById(String.valueOf(id));
    }

    @Override
    public List<Role> findByType(int roletype) {
        return novaRoleDao.query().add(Restrictions.eq("RoleType", roletype)).list();
    }
}
